﻿<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../js/jquery.min.js"></script>
    <script src="../js/jquery.easyui.min.js"></script>
    <script src="../js/easyui-lang-zh_CN.js"></script>
    <link rel="stylesheet" href="../themes/icon.css">
    <link rel="stylesheet" href="../themes/default/easyui.css">
    <link rel="stylesheet" href="../css/wu.css">
    <script>
        var  selectIndex = -1;
        function hideTable(){
            $("#searchdiv").toggle();
        }
 		$(function(){
 		
            $("#productList").datagrid({
                /* fit:true, */
                url:'/kxmanage/osb/show',
             /*    rownumbers:true, */
                pageNumber:1,
                pageSize:5,
                pageList:[5,10,20,30],
                pagination:true,
                showFooter:true,
                columns:[[
                    {field:'ck',checkbox:true},
                    {field:'code',title:'出库单号',width:150,formatter:function(value,row,index){
                    	if(row.code=="true"){
                    	return null;
                    	}
                    	return '<a onclick="showck(\''+row.code+'\')" style="color:blue;text-decoration:underline" href="#">'+row.code+'</a>'
                    }},
                    {field:'outstorageDate',title:'出库日期',width:150},
                    {field:'customName',title:'客户名称',width:173},
                    {field:'amount',title:'数量',width:80},
                    {field:'money',title:'总货值(￥)',width:80},
                    {field:'tuihuo',title:'退货状态',width:78,formatter:function(value,row,index){
                    	if(row.code=="true"){
                    	return null;
                    	}
                    	var str="0.00"
                    	return str;
                    	}}, 
                    {field:'shoukuan',title:'收款情况',width:78,formatter:function(value,row,index){
                    	if(row.code=="true"){
                    	return null;
                    	}
                    	var str="0.00"
                    	return str;
                    	}}, 
                    {field:'kaipiao',title:'开票情况',width:78,formatter:function(value,row,index){
                    	if(row.code=="true"){
                    	return null;
                    	}
                    	var str="0.00"
                    	return str;
                    	}}, 
                    {field:'status',title:'审核',width:80,formatter:function(value,row,index){
                    	if(row.code=="true"){
                    		return null;
                    	}
                    	if(row.checkStatus==1){
                    		return "<span style='color:red'>未审核</span>";
                    	}else if(row.checkStatus==2){
                    		return "已审核";
                    	}
                    	}}, 
                    {field:'str',title:'操作人',width:80,formatter:function(value,row,index){
                    	if(row.code=="true"){
                    	return null;
                    	}
                    	var str="jemo_c"
                    	return str;
                    	}}, 
                   	{field:'opt',title:'操作',width:100,formatter:function (value,row,index) {
                            if(row.code=="true"){
                    	return null;
                    	}
                            var context="<a href=\"javascript:modify('"+row.code+"','"+row.checkStatus+"')\">修改</a>&nbsp;&nbsp;"+
                            "<a href=\"javascript:delob('"+row.code+"','"+row.checkStatus+"')\">删除</a>&nbsp;&nbsp;"
                            return context;
                        }}
                ]],
                toolbar:'#wu_toolbar',
                //不选中行
                onClickRow:function(index,data){
                	$(this).datagrid('unselectRow',index);
                },
                onDblClickRow:function(index,row){
                $("#show").show();
                $("#parttitle").html("单据标号为：<span id='oldCode'>"+row.code+"</span> 的明细如下所列");
                $("#partlist").datagrid({
        		
        		rownumbers:true,
        		url:'/kxmanage/osb/getpart',
        		queryParams:{code:row.code},
        		 columns:[[
                    {field:'ordercode',title:'销售单号',width:150},
                    {field:'code',title:'配件号',width:150},
                    {field:'partName',title:'配件名称',width:173},
                    {field:'partBrand',title:'配件品牌',width:80},
                    {field:'partNo',title:'配件型号',width:100},
                    {field:'amount',title:'数量',width:80},
                    {field:'avg',title:'单价(￥)',width:80},
                    {field:'price',title:'金额(￥)',width:80},
                    {field:'tuihuo',title:'所属仓库',width:78,formatter:function(value,row,index){
                    	if(row.avg==null){
                    		return null;
                    	}
                    	var str="主仓库";
                    	return str;
                    	}}, 
                    
                    {field:'memo',title:'备注',width:135}, 
                   
                ]],
                onClickRow:function(index,data){
                	$(this).datagrid('unselectRow',index);
                },
                onLoadSuccess:function(){
                	$("#partlist").datagrid('appendRow',{
                	'partBrand':"合计",
                	'amount':total('amount'),
                	'price':total('price')
                	});
                }
        	});
                }

            });
            
			$("#search_btn").click(function(){
				var form=$("#form1");
				$("#productList").datagrid('load',serializeForm(form));
			});
        });
        function total(col){
        	var rows=$("#partlist").datagrid('getRows');
        	var total=0;
        	for(var i=0;i<rows.length;i++){
        		total+=parseFloat(rows[i][col]);
        	}
        	return total;
        }
		//将表单序列化        
		function serializeForm(form){
			var obj={};
			$.each(form.serializeArray(),function(index){
				  if(obj[this['name']]){
					obj[this['name']]=obj[this['name']]+','+this['value']
				 }else{
				   obj[this['name']]=this['value'];
				 }
			});
			return obj;
		}
        function detail(id) {//详情(已删除)
            $.messager.alert("信息","查看"+id+"产品详情");
        }
        function showck(id){
        	parent.addTabs("出库单","/kxmanage/osb/findone?code="+id);
        }
        function addProduct() {
            parent.addTabs("出库单","goods/addOuttorageBill.jsp");
        }
        function modify(id,status) {
        	if(status==1){
        		//未审核
            	parent.addTabs("出库单","/kxmanage/osb/modifyone?code="+id);
        	}else{
        		//已审核
        		parent.addTabs("出库单","/kxmanage/osb/modifytwo?code="+id);
        	}
        }
        //多行删除
        function del() {
           var rows=$("#productList").datagrid('getSelections');
            var codes=[];
            for(var i=0;i<rows.length;i++){
               if(rows[i].checkStatus==2){
               	alert("已审核订单不能删除");
               	return;
               }
               codes.push(rows[i].code);
               
            }
            var jsoncodes=JSON.stringify(codes);
            if(rows.length==0){
                $.messager.alert('消息',"请选择记录");
                return
            }
            $.messager.confirm('确认','您确认想要删除记录吗？',function(r){
                if (r==true){
                      $.ajax({
		                type:"post",//请求类型
		                url:"/kxmanage/osb/del?codes="+jsoncodes, 
		                dataType:"json",//ajax接口（请求url）返回的数据类型
		                success:function(data){//data：返回数据（json对象）
		                  if(data.result=="success"){
		                     $.messager.alert('消息',"删除成功");
                             $('#productList').datagrid('reload');//删除后重新加载下
                             var oldCode=$("#oldCode").html();
                             for(var i=0;i<codes.length;i++){
                                if(codes[i]==oldCode){
									$("#show").html("<h3 id='parttitle' style='margin-bottom:10px'></h3><div id='partlist' class='easyui-datagrid'></div>");
                                }
                             }
		                  }else if(data.result=="error"){
		                     $.messager.alert('消息',"删除失败！");
		                  }
		                }
		            }); 
                }
            });
           }
        //单行删除
        function delob(code,status){
        if(status==1){
        	 $.messager.confirm('确认','您确认想要删除记录吗？',function(r){
		   var ids=code;
           if (r==true){
           
              $.ajax({
		      type:"post",//请求类型
		      url:"/kxmanage/osb/delete?code="+code, 
		      dataType:"json",//ajax接口（请求url）返回的数据类型
		      success:function(data){//data：返回数据（json对象）
		         if(data.result=="success"){
		              $.messager.alert('消息',ids+" 删除成功！");
                      $('#productList').datagrid('reload');//删除后重新加载下
                      var oldCode=$("#oldCode").html();
                      if(code==oldCode){
                        $("#show").html("<h3 id='parttitle' style='margin-bottom:10px'></h3><div id='partlist' class='easyui-datagrid'></div>");
                      }
		         }else if(data.result=="error"){
		              $.messager.alert('消息',ids+" 删除失败！");
		         }
		      }
		     }); 
           }
         });
        }else{
			alert("已审核订单不能删除");        
        }
        }
        
        function reload(){
        	location.reload();
        }
        
        function reset(){
        	$("#form1").form('reset');
        }
    </script>

</head>
<body>
<div id="wu_toolbar">
    <div class="wu_toolbar_button">
        <a  href="#" onclick="hideTable()" class="easyui-linkbutton" data-options="iconCls:'icon-search'" plain="true">查询</a>|
        <a  href="#" onclick="addProduct()" class="easyui-linkbutton" data-options="iconCls:'icon-add'" plain="true">添加</a>|
        <a  href="#" onclick="del()" class="easyui-linkbutton" data-options="iconCls:'icon-delete-self'" plain="true">删除</a>|
        <a  href="#" onclick="reload()" class="easyui-linkbutton" data-options="iconCls:'icon-page-refresh'" plain="true">刷新</a>|
        <a  href="#" onclick="reload()" class="easyui-linkbutton" data-options="iconCls:'icon-communication'" plain="true">导出excal</a>
    </div>
    <div id="searchdiv" style="display: block;width: 100%;">
        <form name="form1" id="form1" action="/kxmanage/osb/show" method="post">
		<input name="page" value="1" type="hidden"/>
		<input name="rows" value="5" type="hidden"/>
            <table width="100%" border="0" cellspacing="0" style="background-color:#c9dfff;" >
                <tbody><tr>
                    <td width="70"><b>检索条件:</b></td>
                    <td width="70" align="right">出库单号:</td>
                    <td width="150" align="left"><input name="findcode" class="easyui-textbox" type="text" id="findcode" value="" maxlength="100"></td>
                    <td width="70" align="right">开始日期:</td>
                    <td width="150" align="left"><div class="l-text-wrapper"><div class="l-text l-text-date"><input name="findstartDate" type="text" id="findstartDate" value="" maxlength="30" class="easyui-datebox" ligeruiid="findstartDate"><div class="l-text-l"></div><div class="l-text-r"></div><div class="l-trigger"><div class="l-trigger-icon"></div></div></div></div></td>
                    <td width="70" align="right">结束日期:</td>
                    <td width="150" align="left"><div class="l-text-wrapper"><div class="l-text l-text-date"><input name="findendDate" type="text" id="findendDate" value="" maxlength="30" class="easyui-datebox" ligeruiid="findendDate"><div class="l-text-l"></div><div class="l-text-r"></div><div class="l-trigger"><div class="l-trigger-icon"></div></div></div></div></td>
                    <td width="70" align="right">客户名称:</td>
                    <td width="150" align="left"><input name="findsupplierName" class="easyui-textbox" type="text" id="findsupplierName" value="" maxlength="100"></td>
                    <td width="72">
                        <a id="search_btn" href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-search'">搜索</a>
                    </td>
                    <td width="72">
                        <a id="reset_btn" href="#" onclick="reset()" class="easyui-linkbutton" data-options="iconCls:'icon-refresh'">重置</a>
                    </td>
                    <td width="0"></td>


                </tr>
                </tbody>
            </table>
            <input type="hidden" id="menuCode" value="100001001">
        </form>
    </div>
</div>
<div id="productList" class="easyui-datagrid">

</div>
<div id="show" style="display:none">
<h3 id="parttitle" style="margin:10px 0"></h3>
<div id="partlist"></div>
</div>
</body>
</html>